/// @tags: Tree
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

namespace BlueQuantum {

int const N = 1e6 + 5, maxm = 2000035;

int n, a_cnt, leg, sum, e_cnt;
int siz[N], maxn[N], anc[N], ans[N], heads[N];

struct Edge {
  int v, nxt;
} e[N * 2];

inline void add(int u, int v) {
  e[++e_cnt].v = v, e[e_cnt].nxt = heads[u], heads[u] = e_cnt;
}

int getRoot(int u, int fa) {
  maxn[u] = 0, siz[u] = 1;
  int rt = 0;
  for (int i = heads[u]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == fa) continue;
    int vrt = getRoot(v, u);
    siz[u] += siz[v];
    if (rt == 0 || maxn[vrt] < maxn[rt]) rt = vrt;
    maxn[u] = std::max(maxn[u], siz[v]);
  }
  maxn[u] = std::max(maxn[u], n - siz[u]);
  if (rt == 0 || maxn[u] < maxn[rt]) rt = u;
  return rt;
}

inline bool cmp(int x, int y) { return siz[x] > siz[y]; }

void dfs(int x, int fa, int c) {
  ans[x] = (leg - 1) + ((n - c - siz[x]) * 2 > n);
  for (int i = heads[x]; i; i = e[i].nxt)
    if (e[i].v != fa) dfs(e[i].v, x, c);
}

inline int main() {
  cin >> n;
  for (int i = 1, u, v; i < n; ++i) {
    cin >> u >> v;
    add(u, v), add(v, u);
  }
  int rt = getRoot(1, 0);
  getRoot(rt, 0);
  for (int i = heads[rt]; i; i = e[i].nxt) anc[++a_cnt] = e[i].v;
  sort(anc + 1, anc + a_cnt + 1, cmp);
  for (int i = 1; i <= a_cnt; ++i) {
    sum += siz[anc[i]], ++leg;
    if (sum * 2 >= n) break;
  }
  for (int i = 1; i <= a_cnt; ++i)
    dfs(anc[i], rt, sum - std::max(siz[anc[i]], siz[anc[leg]]));
  for (int i = 1; i <= n; ++i) cout << ans[i] << '\n';
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("minister.in", "r", stdin);
  freopen("minister.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
